//jialili:订单管理模拟数据
import Mock from "mockjs";
let {data} = Mock.mock({
  "data|20": [ //生成20条数据
      {
          "shopId|+1": 1,  //生成商品id，自增1
          "orderPO":122253673341,  // 订单编号
          "price|30-200": 30,  //随机生成商品价格 在30-1000之间
          "num|1-10" :2,    //随机生成商品数量 在1-10之间
          "totalSrice":"",   // 实付金额23423
          "payBefore":300,   // 快速金额300
          "name":"@ctitle(3)", // 收货人
          "shopAddress": "@county(true)", //随机生成地址
          "doneSrice":"",   // 成交金额23423
          "orderStatus":"已完成",  //订单状态
          "payWay":"微信" , // 支付方式
          "checked" : false,
          "flag" : false           
      }
  ]
})


class OrderServe {
  getData(params){
    const { pageSize, currentPage } = params;
    const result = data.slice(
      (currentPage-1)*pageSize,currentPage*pageSize
    );
    return new Promise((resolve)=>{
      resolve({
        status:0,
        list:result,
        count:data.length
      })
    })
  }

  addData(params,obj) {
    // console.log(params);
    data.splice(params,0,obj);
    return new Promise((resolve) => {
      resolve({
        status: 0,
        msg: "添加成功",
      });
    });
  }

  removeData(params) {
  data = data.filter(item=>item.shopId!==params)
    return new Promise((resolve) => {
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
  delDatas(params){
    for(let i=0;i<params.length;i++) {
      data = data.filter(item=>item.shopId!== params[i])
      return new Promise((resolve) => {
        resolve({
          status: 0,
          msg: "删除成功",
        });
      });
    }
  }
}
const datas = new OrderServe();
export default datas;


// Mock.mock(/indent\/allindents/, 'post', () => { //三个参数。第一个路径，第二个请求方式post/get，第三个回调，返回值
//     return data
// })